/**
 * @author Renato Lui Geh
 * @author Yan Soares Couto
 * 
 * @version 0.0.1
 * 
 * 12/06/2011
 * 
 */

package zombies;

import javax.swing.*;
import java.awt.*;
import java.util.*;

public class Zombie01 {
    private final int panelWidth = Zombies.WIDTH;
    private final int panelHeight = Zombies.HEIGHT;
    private boolean directionsException;
    private boolean isPositive;
    private String enemy = "Zombie_01.gif";
    private Image enemyImage;
    private ImageIcon enemyIcon;
    private int pos_x, pos_y;
    private int dx, dy;
    private int width, height;
    private Random rand = new Random();
    
    public Zombie01(int pos_x, int pos_y) {
        enemyIcon = new ImageIcon(this.getClass().getResource(enemy));
        enemyImage = enemyIcon.getImage();
        
        width = enemyImage.getWidth(null);
        height = enemyImage.getHeight(null);
        
        directionsException = getDirections();
         
        this.pos_x = pos_x;
        this.pos_y = pos_y;
    }
    public Zombie01(ArrayList<Zombie01> zombies) {
        enemyIcon = new ImageIcon(this.getClass().getResource(enemy));
        enemyImage = enemyIcon.getImage();
        
        width = enemyImage.getWidth(null);
        height = enemyImage.getHeight(null);
        
        directionsException = getDirections();
        
        pos_x = rand.nextInt(Zombies.WIDTH) + 1;
        pos_y = rand.nextInt(Zombies.HEIGHT) + 1;
    }
    public Zombie01() {
        enemyIcon = new ImageIcon(this.getClass().getResource(enemy));
        enemyImage = enemyIcon.getImage();
        
        width = enemyImage.getWidth(null);
        height = enemyImage.getHeight(null);
        
        directionsException = getDirections();
        
        pos_x = rand.nextInt(Zombies.WIDTH) + 1;
        pos_y = rand.nextInt(Zombies.HEIGHT) + 1;
    }
    public void move() {       
        pos_x += dx;
        pos_y += dy;
        
        if(pos_x < 1 || pos_x > panelWidth - 35)
            dx = -dx;
        if(pos_y < 1 || pos_y > panelHeight - 50)
            dy = -dy;
    }
    public boolean getDirections() {
        try {
            isPositive = rand.nextBoolean();
            if(isPositive == true)
                dx = 1;
            else dx = -1;

            isPositive = rand.nextBoolean();
            if(isPositive == true)
                dy = 1;
            else dy = -1;

            return true;
        }
        catch(Exception randomException) {
            randomException.printStackTrace();
            return false;
        }
    }
    /**
     * @deprecated
     * 
     * @return Returns a boolean. 
     * True if the application was able to set the direction of the Zombie.
     * False if the application failed to set the direction of the Zombie.
     * 
     * Prints the exception if the method returns false.
     */
    public boolean getDir() {
        try {
            dx = (int)(Math.random() * 5 + 1);
            dy = (int)(Math.random() * 5 + 1);

            return true;
        }
        catch(Exception randomException) {
            randomException.printStackTrace();
            return false;
        }
    }
    public Image getImage() {
        return enemyImage;
    }
    public int getX() {
        return pos_x;
    }
    public int getY() {
        return pos_y;
    }
    public Rectangle getBounds() {
        return new Rectangle(pos_x, pos_y, width, height);
    }
}
